import { execute } from "../../database/connector";

import { FileQueries } from "../queries/file.query";
import { IFile } from "../../models/file.model";

/**
 * gets active files
 */
export const getFiles = async () => {
  return execute<IFile[]>(FileQueries.GetFiles, []);
};

/**
 * gets a file based on id provided
 */
export const getFileById = async (id: IFile['id']) => {
  return execute<IFile>(FileQueries.GetFileById, [id]);
};


/**
 * adds a new active file record
 */
export const insertFile = async (file: IFile) => {
  const result = await execute<{ affectedRows: number }>(FileQueries.AddFile, [
    Object.values(file)
  ]);
  return result.affectedRows > 0;
};


/**
 * updates file information based on the id provided
 */
 export const deleteFile = async (id: IFile['id']) => {
  const result = await execute<{ affectedRows: number }>(FileQueries.DeleteFileById, [
    id
  ]);
  return result.affectedRows > 0;
};